/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package isvp.implementations;

import isvp.constants.ComponentConstants;
import isvp.interfaces.Application;
import isvp.utilities.XMLUtils;
import org.w3c.dom.Document;

/**
 * Implementation for the Application interface.
 * @author jjophin
 */
public class ApplicationImpl implements Application{
    private Document applicationXML;
    private String applicationFileName;
    protected String applicationId;
    protected String applicationName;
    protected String tenantId;
    protected String applicationDescription;
    protected String applicationLanguageCode;
    protected String applicationCreatedDate;
    
    /**
     * Constructor
     * @param xml : The details about the application will be placed in an XML file in the ISVP. 
     * The name of this file is present in the UCImporter/Application tag in isv.xml. The xml content 
     * in this file has to be passed as a Document to this parameter.
     * @param fileName : The name of the xml file corresponding to application details in the ISVP
     */
    public ApplicationImpl(Document xml, String fileName) {
        applicationXML = xml;
        applicationFileName = fileName;
        setApplicationCreatedDate();
        setApplicationDescription();
        setApplicationId();
        setApplicationLanguageCode();
        setApplicationName();
        setTenantId();
    }
    
    /**
     * Returns the file name of the xml file corresponding to application details in the ISVP
     * @return String
     */
    @Override
    public String getApplicationFileName() {
        return applicationFileName;
    }
    
    /**
     * Returns application id
     * @return 
     */
    @Override
    public String getApplicationId() {
        return applicationId;
    }
    
    /**
     * Returns application name
     * @return 
     */
    @Override
    public String getApplicationName() {
        return applicationName;    }
    
    /**
     * Returns the tenant id of the tenant in which the application was packed
     * @return 
     */
    @Override
    public String getTenantId() {
        return tenantId;
    }
    
    /**
     * Returns application description
     * @return 
     */
    @Override
    public String getApplicationDescription() {
        return applicationDescription;    
    }
    
    /**
     * Returns application language code
     * @return 
     */
    @Override
    public String getApplicationLanguageCode() {
        return applicationLanguageCode;
    }
    
    /**
     * Returns the created date of the ISVP
     * @return 
     */
    @Override
    public String getApplicationCreatedDate() {
        return applicationCreatedDate;
    }
    
    public void setApplicationCreatedDate() {
        this.applicationCreatedDate = XMLUtils.getTextContent(applicationXML, ComponentConstants.APPLICATION_CREATED_DATE_XPATH);
    }

    public void setApplicationDescription() {
        this.applicationDescription = XMLUtils.getTextContent(applicationXML, ComponentConstants.APPLICATION_DESCRIPTION_XPATH);
    }

    public void setApplicationFileName(String applicationFileName) {
        this.applicationFileName = applicationFileName;
    }

    public void setApplicationId() {
        this.applicationId = XMLUtils.getTextContent(applicationXML, ComponentConstants.APPLICATION_ID_XPATH);
    }

    public void setApplicationLanguageCode() {
        this.applicationLanguageCode = XMLUtils.getTextContent(applicationXML, ComponentConstants.APPLICATION_LANGUAGE_CODE_XPATH);
    }

    public void setApplicationName() {
        this.applicationName = XMLUtils.getTextContent(applicationXML, ComponentConstants.APPLICATION_NAME_XPATH);
    }

    public void setApplicationXML(Document applicationXML) {
        this.applicationXML = applicationXML;
    }

    public void setTenantId() {
        this.tenantId = XMLUtils.getTextContent(applicationXML, ComponentConstants.APPLICATION_TENANT_ID_XPATH);
    }   
}
